{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "densent.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python2",
      "display_name": "Python 2"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KXE-pP4W42Fq",
        "colab_type": "text"
      },
      "source": [
        "## 运行环境为python2"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Zf7tU-Qy4w3B",
        "colab_type": "code",
        "outputId": "92e6ce1f-e831-40cc-b06c-e1b6db83d57f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        }
      },
      "source": [
        "!pip list"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Package                            Version              \n",
            "---------------------------------- ---------------------\n",
            "absl-py                            0.7.1                \n",
            "aenum                              2.1.2                \n",
            "alabaster                          0.7.12               \n",
            "albumentations                     0.1.12               \n",
            "altair                             3.1.0                \n",
            "astor                              0.8.0                \n",
            "astropy                            2.0.14               \n",
            "atari-py                           0.1.7                \n",
            "atomicwrites                       1.3.0                \n",
            "attrs                              19.1.0               \n",
            "audioread                          2.1.8                \n",
            "autograd                           1.2                  \n",
            "Babel                              2.7.0                \n",
            "backports-abc                      0.5                  \n",
            "backports.functools-lru-cache      1.5                  \n",
            "backports.shutil-get-terminal-size 1.0.0                \n",
            "backports.tempfile                 1.0                  \n",
            "backports.weakref                  1.0.post1            \n",
            "bcolz                              1.2.1                \n",
            "beautifulsoup4                     4.6.3                \n",
            "bleach                             3.1.0                \n",
            "blis                               0.2.4                \n",
            "bokeh                              1.0.4                \n",
            "boto                               2.49.0               \n",
            "boto3                              1.9.174              \n",
            "botocore                           1.12.174             \n",
            "branca                             0.3.1                \n",
            "bs4                                0.0.1                \n",
            "bz2file                            0.98                 \n",
            "cachetools                         3.1.1                \n",
            "certifi                            2019.6.16            \n",
            "cffi                               1.12.3               \n",
            "chainer                            5.4.0                \n",
            "chardet                            3.0.4                \n",
            "cityhash                           0.2.3.post9          \n",
            "Click                              7.0                  \n",
            "click-plugins                      1.1.1                \n",
            "cligj                              0.5.0                \n",
            "cloudpickle                        0.6.1                \n",
            "cmake                              3.12.0               \n",
            "colorlover                         0.3.0                \n",
            "community                          1.0.0b1              \n",
            "configparser                       3.7.4                \n",
            "contextlib2                        0.5.5                \n",
            "convertdate                        2.1.3                \n",
            "crcmod                             1.7                  \n",
            "cufflinks                          0.14.6               \n",
            "cupy-cuda100                       5.4.0                \n",
            "cvxopt                             1.2.3                \n",
            "cvxpy                              1.0.15               \n",
            "cycler                             0.10.0               \n",
            "cymem                              2.0.2                \n",
            "Cython                             0.29.10              \n",
            "daft                               0.0.4                \n",
            "dask                               1.1.5                \n",
            "decorator                          4.4.0                \n",
            "defusedxml                         0.6.0                \n",
            "descartes                          1.1.0                \n",
            "dill                               0.2.9                \n",
            "distributed                        1.25.3               \n",
            "Django                             1.11.21              \n",
            "dlib                               19.16.0              \n",
            "dm-sonnet                          1.33                 \n",
            "docutils                           0.14                 \n",
            "dopamine-rl                        1.0.5                \n",
            "easydict                           1.9                  \n",
            "ecos                               2.0.7.post1          \n",
            "editdistance                       0.5.3                \n",
            "en-core-web-sm                     2.1.0                \n",
            "entrypoints                        0.3                  \n",
            "enum34                             1.1.6                \n",
            "ephem                              3.7.6.0              \n",
            "et-xmlfile                         1.0.1                \n",
            "fa2                                0.3.5                \n",
            "fancyimpute                        0.4.3                \n",
            "fastai                             0.7.0                \n",
            "fastcache                          1.1.0                \n",
            "fastdtw                            0.3.2                \n",
            "fastrlock                          0.4                  \n",
            "fbprophet                          0.5                  \n",
            "feather-format                     0.4.0                \n",
            "featuretools                       0.4.1                \n",
            "filelock                           3.0.12               \n",
            "Fiona                              1.8.6                \n",
            "fix-yahoo-finance                  0.0.22               \n",
            "Flask                              1.0.3                \n",
            "folium                             0.8.3                \n",
            "funcsigs                           1.0.2                \n",
            "functools32                        3.2.3.post2          \n",
            "future                             0.16.0               \n",
            "futures                            3.2.0                \n",
            "gast                               0.2.2                \n",
            "GDAL                               2.2.2                \n",
            "gdown                              3.6.4                \n",
            "gensim                             3.6.0                \n",
            "geographiclib                      1.49                 \n",
            "geopandas                          0.5.0                \n",
            "geopy                              1.17.0               \n",
            "gevent                             1.4.0                \n",
            "gin-config                         0.1.4                \n",
            "glob2                              0.7                  \n",
            "google                             2.0.2                \n",
            "google-api-core                    1.12.0               \n",
            "google-api-python-client           1.7.9                \n",
            "google-auth                        1.4.2                \n",
            "google-auth-httplib2               0.0.3                \n",
            "google-auth-oauthlib               0.4.0                \n",
            "google-cloud-bigquery              1.14.0               \n",
            "google-cloud-core                  1.0.2                \n",
            "google-cloud-datastore             1.8.0                \n",
            "google-cloud-language              1.2.0                \n",
            "google-cloud-storage               1.16.1               \n",
            "google-cloud-translate             1.5.0                \n",
            "google-colab                       1.0.0                \n",
            "google-pasta                       0.1.7                \n",
            "google-resumable-media             0.3.2                \n",
            "googleapis-common-protos           1.6.0                \n",
            "googledrivedownloader              0.4                  \n",
            "graph-nets                         1.0.4                \n",
            "graphviz                           0.10.1               \n",
            "greenlet                           0.4.15               \n",
            "grpcio                             1.15.0               \n",
            "gspread                            3.0.1                \n",
            "gspread-dataframe                  3.0.2                \n",
            "gunicorn                           19.9.0               \n",
            "gym                                0.10.11              \n",
            "h5py                               2.8.0                \n",
            "HeapDict                           1.0.0                \n",
            "holidays                           0.9.10               \n",
            "html5lib                           1.0.1                \n",
            "httpimport                         0.5.16               \n",
            "httplib2                           0.11.3               \n",
            "humanize                           0.5.1                \n",
            "hyperopt                           0.1.2                \n",
            "ideep4py                           2.0.0.post3          \n",
            "idna                               2.8                  \n",
            "image                              1.5.27               \n",
            "imageio                            2.4.1                \n",
            "imagesize                          1.1.0                \n",
            "imbalanced-learn                   0.4.3                \n",
            "imblearn                           0.0                  \n",
            "imgaug                             0.2.9                \n",
            "imutils                            0.5.2                \n",
            "inflect                            2.1.0                \n",
            "intel-openmp                       2019.0               \n",
            "intervaltree                       2.1.0                \n",
            "ipaddress                          1.0.22               \n",
            "ipykernel                          4.6.1                \n",
            "ipython                            5.5.0                \n",
            "ipython-genutils                   0.2.0                \n",
            "ipython-sql                        0.3.9                \n",
            "ipywidgets                         7.4.2                \n",
            "isoweek                            1.3.3                \n",
            "itsdangerous                       1.1.0                \n",
            "jdcal                              1.4.1                \n",
            "jedi                               0.14.0               \n",
            "jieba                              0.39                 \n",
            "Jinja2                             2.10.1               \n",
            "jmespath                           0.9.4                \n",
            "joblib                             0.12.5               \n",
            "jpeg4py                            0.1.4                \n",
            "jsonschema                         2.6.0                \n",
            "jupyter                            1.0.0                \n",
            "jupyter-client                     5.2.4                \n",
            "jupyter-console                    5.2.0                \n",
            "jupyter-core                       4.5.0                \n",
            "kaggle                             1.5.4                \n",
            "kapre                              0.1.3.1              \n",
            "Keras                              2.2.4                \n",
            "Keras-Applications                 1.0.8                \n",
            "Keras-Preprocessing                1.1.0                \n",
            "keras-vis                          0.4.1                \n",
            "kiwisolver                         1.1.0                \n",
            "knnimpute                          0.1.0                \n",
            "librosa                            0.6.3                \n",
            "lightgbm                           2.2.3                \n",
            "llvmlite                           0.29.0               \n",
            "lmdb                               0.95                 \n",
            "lucid                              0.3.8                \n",
            "lunardate                          0.2.0                \n",
            "lxml                               4.2.6                \n",
            "magenta                            0.3.19               \n",
            "Markdown                           3.1.1                \n",
            "MarkupSafe                         1.1.1                \n",
            "matplotlib                         2.2.4                \n",
            "matplotlib-venn                    0.11.5               \n",
            "mesh-tensorflow                    0.0.5                \n",
            "mido                               1.2.6                \n",
            "mir-eval                           0.5                  \n",
            "missingno                          0.4.1                \n",
            "mistune                            0.8.4                \n",
            "mizani                             0.4.6                \n",
            "mkl                                2019.0               \n",
            "mlxtend                            0.14.0               \n",
            "mock                               2.0.0                \n",
            "more-itertools                     5.0.0                \n",
            "moviepy                            0.2.3.5              \n",
            "mpmath                             1.1.0                \n",
            "msgpack                            0.5.6                \n",
            "multiprocess                       0.70.7               \n",
            "multitasking                       0.0.9                \n",
            "munch                              2.3.2                \n",
            "murmurhash                         1.0.2                \n",
            "music21                            4.1.0                \n",
            "natsort                            5.5.0                \n",
            "nbconvert                          5.5.0                \n",
            "nbformat                           4.4.0                \n",
            "networkx                           2.2                  \n",
            "nibabel                            2.3.3                \n",
            "nltk                               3.2.5                \n",
            "nose                               1.3.7                \n",
            "notebook                           5.2.2                \n",
            "np-utils                           0.5.10.0             \n",
            "numba                              0.40.1               \n",
            "numexpr                            2.6.9                \n",
            "numpy                              1.16.4               \n",
            "oauth2client                       4.1.3                \n",
            "oauthlib                           3.0.1                \n",
            "okgrade                            0.4.3                \n",
            "olefile                            0.46                 \n",
            "opencv-contrib-python              3.4.3.18             \n",
            "opencv-python                      3.4.5.20             \n",
            "openpyxl                           2.5.9                \n",
            "osqp                               0.5.0                \n",
            "packaging                          19.0                 \n",
            "palettable                         3.1.1                \n",
            "pandas                             0.24.2               \n",
            "pandas-datareader                  0.7.0                \n",
            "pandas-gbq                         0.4.1                \n",
            "pandas-profiling                   1.4.1                \n",
            "pandas-summary                     0.0.6                \n",
            "pandocfilters                      1.4.2                \n",
            "parso                              0.5.0                \n",
            "pathlib                            1.0.1                \n",
            "pathlib2                           2.3.3                \n",
            "patsy                              0.5.1                \n",
            "pbr                                5.3.1                \n",
            "pexpect                            4.7.0                \n",
            "pickleshare                        0.7.5                \n",
            "Pillow                             4.3.0                \n",
            "pip                                19.1.1               \n",
            "pip-tools                          3.6.1                \n",
            "plac                               0.9.6                \n",
            "plotly                             3.6.1                \n",
            "plotnine                           0.4.0                \n",
            "pluggy                             0.7.1                \n",
            "portpicker                         1.2.0                \n",
            "prefetch-generator                 1.0.1                \n",
            "preshed                            2.0.1                \n",
            "pretty-midi                        0.2.8                \n",
            "prettytable                        0.7.2                \n",
            "progressbar2                       3.38.0               \n",
            "prometheus-client                  0.7.1                \n",
            "promise                            2.2.1                \n",
            "prompt-toolkit                     1.0.16               \n",
            "protobuf                           3.7.1                \n",
            "psutil                             5.4.8                \n",
            "psycopg2                           2.7.6.1              \n",
            "ptyprocess                         0.6.0                \n",
            "py                                 1.8.0                \n",
            "pyarrow                            0.13.0               \n",
            "pyasn1                             0.4.5                \n",
            "pyasn1-modules                     0.2.5                \n",
            "pycocotools                        2.0.0                \n",
            "pycparser                          2.19                 \n",
            "pydot                              1.3.0                \n",
            "pydot-ng                           2.0.0                \n",
            "pydotplus                          2.0.2                \n",
            "pyemd                              0.5.1                \n",
            "pyglet                             1.3.2                \n",
            "Pygments                           2.1.3                \n",
            "pymc3                              3.6                  \n",
            "pymongo                            3.8.0                \n",
            "pymystem3                          0.2.0                \n",
            "PyOpenGL                           3.1.0                \n",
            "pyparsing                          2.4.0                \n",
            "pyproj                             2.2.1                \n",
            "pyrsistent                         0.15.2               \n",
            "pysndfile                          1.3.3                \n",
            "PySocks                            1.7.0                \n",
            "pystan                             2.19.0.0             \n",
            "pytest                             3.6.4                \n",
            "python-chess                       0.23.11              \n",
            "python-dateutil                    2.5.3                \n",
            "python-louvain                     0.13                 \n",
            "python-rtmidi                      1.3.0                \n",
            "python-slugify                     3.0.2                \n",
            "python-utils                       2.3.0                \n",
            "pytz                               2018.9               \n",
            "PyWavelets                         1.0.3                \n",
            "PyYAML                             3.13                 \n",
            "pyzmq                              17.0.0               \n",
            "qtconsole                          4.5.1                \n",
            "requests                           2.21.0               \n",
            "requests-oauthlib                  1.2.0                \n",
            "resampy                            0.2.1                \n",
            "retrying                           1.3.3                \n",
            "rpy2                               2.8.6                \n",
            "rsa                                4.0                  \n",
            "s3fs                               0.2.1                \n",
            "s3transfer                         0.2.1                \n",
            "scandir                            1.10.0               \n",
            "scikit-image                       0.14.3               \n",
            "scikit-learn                       0.20.3               \n",
            "scipy                              1.2.2                \n",
            "scs                                2.1.0                \n",
            "seaborn                            0.9.0                \n",
            "semantic-version                   2.6.0                \n",
            "Send2Trash                         1.5.0                \n",
            "setuptools                         41.0.1               \n",
            "setuptools-git                     1.2                  \n",
            "Shapely                            1.6.4.post2          \n",
            "simplegeneric                      0.8.1                \n",
            "singledispatch                     3.4.0.3              \n",
            "six                                1.12.0               \n",
            "sklearn                            0.0                  \n",
            "sklearn-pandas                     1.8.0                \n",
            "smart-open                         1.8.4                \n",
            "snowballstemmer                    1.2.1                \n",
            "sortedcontainers                   2.1.0                \n",
            "spacy                              2.1.4                \n",
            "Sphinx                             1.8.5                \n",
            "sphinxcontrib-websupport           1.1.2                \n",
            "SQLAlchemy                         1.3.5                \n",
            "sqlparse                           0.3.0                \n",
            "srsly                              0.0.7                \n",
            "statsmodels                        0.10.0               \n",
            "subprocess32                       3.5.4                \n",
            "sympy                              1.1.1                \n",
            "tables                             3.4.4                \n",
            "tabulate                           0.8.3                \n",
            "tblib                              1.4.0                \n",
            "tensor2tensor                      1.11.0               \n",
            "tensorboard                        1.13.1               \n",
            "tensorboardcolab                   0.0.22               \n",
            "tensorflow                         1.14.0rc1            \n",
            "tensorflow-estimator               1.14.0               \n",
            "tensorflow-hub                     0.4.0                \n",
            "tensorflow-metadata                0.13.0               \n",
            "tensorflow-probability             0.7.0rc0             \n",
            "termcolor                          1.1.0                \n",
            "terminado                          0.8.2                \n",
            "testpath                           0.4.2                \n",
            "text-unidecode                     1.2                  \n",
            "textblob                           0.15.3               \n",
            "tfds-nightly                       1.0.2.dev201906240105\n",
            "tflearn                            0.3.2                \n",
            "Theano                             1.0.4                \n",
            "thinc                              7.0.4                \n",
            "toolz                              0.9.0                \n",
            "torch                              1.1.0                \n",
            "torchsummary                       1.5.1                \n",
            "torchtext                          0.3.1                \n",
            "torchvision                        0.3.0                \n",
            "tornado                            4.5.3                \n",
            "tqdm                               4.28.1               \n",
            "traitlets                          4.3.2                \n",
            "tweepy                             3.6.0                \n",
            "typing                             3.7.4                \n",
            "tzlocal                            1.5.1                \n",
            "umap-learn                         0.3.9                \n",
            "uritemplate                        3.0.0                \n",
            "urllib3                            1.24.3               \n",
            "vega-datasets                      0.7.0                \n",
            "wasabi                             0.2.2                \n",
            "wcwidth                            0.1.7                \n",
            "webencodings                       0.5.1                \n",
            "Werkzeug                           0.15.4               \n",
            "wheel                              0.33.4               \n",
            "widgetsnbextension                 3.4.2                \n",
            "wordcloud                          1.5.0                \n",
            "wrapt                              1.11.2               \n",
            "xarray                             0.11.3               \n",
            "xgboost                            0.82                 \n",
            "xlrd                               1.1.0                \n",
            "xlwt                               1.3.0                \n",
            "yellowbrick                        0.9.1                \n",
            "zict                               0.1.4                \n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZIO4KNsLmmrp",
        "colab_type": "code",
        "outputId": "79283a51-3ada-4ef1-eb6f-d6fa8346d649",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 207
        }
      },
      "source": [
        "!pip install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp27-cp27mu-linux_x86_64.whl\n",
        "!pip install https://download.pytorch.org/whl/cu100/torchvision-0.3.0-cp27-cp27mu-linux_x86_64.whl"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Requirement already satisfied: torch==1.1.0 from https://download.pytorch.org/whl/cu100/torch-1.1.0-cp27-cp27mu-linux_x86_64.whl in /usr/local/lib/python2.7/dist-packages (1.1.0)\n",
            "Requirement already satisfied: future in /usr/local/lib/python2.7/dist-packages (from torch==1.1.0) (0.16.0)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from torch==1.1.0) (1.16.4)\n",
            "Requirement already satisfied: torchvision==0.3.0 from https://download.pytorch.org/whl/cu100/torchvision-0.3.0-cp27-cp27mu-linux_x86_64.whl in /usr/local/lib/python2.7/dist-packages (0.3.0)\n",
            "Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from torchvision==0.3.0) (1.12.0)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from torchvision==0.3.0) (1.16.4)\n",
            "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python2.7/dist-packages (from torchvision==0.3.0) (4.3.0)\n",
            "Requirement already satisfied: torch>=1.1.0 in /usr/local/lib/python2.7/dist-packages (from torchvision==0.3.0) (1.1.0)\n",
            "Requirement already satisfied: olefile in /usr/local/lib/python2.7/dist-packages (from pillow>=4.1.1->torchvision==0.3.0) (0.46)\n",
            "Requirement already satisfied: future in /usr/local/lib/python2.7/dist-packages (from torch>=1.1.0->torchvision==0.3.0) (0.16.0)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Rj5QU79Jm1YW",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!git clone https://github.com/yinchangchang/ocr_densenet.git"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T6MxsYl5m8pv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cd ./ocr_densenet;pip install -r requirement.txt"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JOE1Ok7inUAC",
        "colab_type": "code",
        "outputId": "6f763fd8-b776-4ce6-caa6-bd0130471a1d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 204
        }
      },
      "source": [
        "import pandas as pd\n",
        "data = pd.read_csv('./ocr_densenet/files/train.csv')\n",
        "data.head()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>name</th>\n",
              "      <th>content</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>GK5NXT2E.jpg</td>\n",
              "      <td>SJ88154371</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>PNFRISAL.jpg</td>\n",
              "      <td>XI90599371</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2GVHF7RK.jpg</td>\n",
              "      <td>WG35669371</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>DGUVOETG.jpg</td>\n",
              "      <td>YH01075371</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>ARIQMNK3.jpg</td>\n",
              "      <td>SJ44155371</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "           name      content\n",
              "0  GK5NXT2E.jpg   SJ88154371\n",
              "1  PNFRISAL.jpg   XI90599371\n",
              "2  2GVHF7RK.jpg   WG35669371\n",
              "3  DGUVOETG.jpg   YH01075371\n",
              "4  ARIQMNK3.jpg   SJ44155371"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "t_LULywmqlOa",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# !mkdir ./ocr_densenet/data\n",
        "# !cp ./drive/my_gpu/tinymind/test_cptn_result.zip ./;unzip test_cptn_result.zip\n",
        "!cp ./drive/my_gpu/tinymind/train_cptn_result.zip ./;unzip train_cptn_result.zip"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "g6QI4-Qfw-pH",
        "colab_type": "text"
      },
      "source": [
        "###将模型copy到此目录下"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZiOmRTapRZHb",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cd ocr_densenet/code/ocr;mkdir -p ../../data/models-small/densenet/eval-16-1/"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Apjh5eJIwW9Z",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cd ocr_densenet/code/ocr;python main.py --phase train --resume ../../data/models-small/densenet/eval-16-1/best_f1score.ckpt"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6IpcOB1ZPFCM",
        "colab_type": "code",
        "outputId": "14227400-baa8-44a2-9c36-0986334bcfb0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        }
      },
      "source": [
        "!cd ocr_densenet/code/ocr;python main.py --phase test --resume ../../data/models-small/densenet/eval-16-1/best_f1score.ckpt"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "best_f1score 0.999665101417\n",
            "('len(train_filelist1)', 0)\n",
            "('len(train_filelist2)', 0)\n",
            "\n",
            "test test_files, epoch: 13\n",
            "../../data/feats/test\n",
            " 70% 7024/10000 [02:56<01:14, 39.87it/s]P5MUY42D.jpg\n",
            "100% 10000/10000 [04:07<00:00, 40.46it/s]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Dv7BqA1F5RtR",
        "colab_type": "text"
      },
      "source": [
        "### 根据 20_test_preds_max1.npy 中各个字符的概率,将不满足正则的数据进行重新整理，提高一个百分点"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5yod-YpIp2U-",
        "colab_type": "code",
        "outputId": "fa149988-8442-4891-ffba-a22a2d47ff44",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        }
      },
      "source": [
        "import json\n",
        "import math\n",
        "word_index_dict = json.load(open('/content/ocr_densenet/files/alphabet_index_dict.json'))\n",
        "index_word_dict = { v:k for k,v in word_index_dict.items() }\n",
        "\n",
        "import pandas as pd\n",
        "import re\n",
        "import numpy as np\n",
        "probs = np.load(\"./ocr_densenet/data/result/21_test_preds_max1.npy\",allow_pickle=True)\n",
        "print(probs.shape)\n",
        "\n",
        "def pst10(p):\n",
        "  mid=[]\n",
        "  for i in range(64):\n",
        "    max = -4\n",
        "    w = '*'\n",
        "    for j in range(len(p[i])):\n",
        "      if p[i][j]>max:\n",
        "        max = p[i][j]\n",
        "        w = index_word_dict[j]\n",
        "    mid.append(w)\n",
        "  print(''.join(mid))\n",
        "  result=[]\n",
        "  lx =0\n",
        "  last = '*'\n",
        "  for i in mid:\n",
        "    if i != '*' and last=='*':\n",
        "      result.append(i)\n",
        "      last = i\n",
        "      lx = 1\n",
        "    elif i!= '*' and last!=i:\n",
        "      result.append(i)\n",
        "      last = i\n",
        "      lx = 1\n",
        "    elif i!='*' and last==i and lx >3:\n",
        "      result.append(i)\n",
        "      last = i\n",
        "      lx = 1\n",
        "    elif i!= '*' and last==i:\n",
        "#       last = i\n",
        "      lx = lx +1\n",
        "    else:\n",
        "      last = i\n",
        "      lx = 1\n",
        "  return ''.join(result)\n",
        "\n",
        "def pgt10(p):\n",
        "  result = []\n",
        "  mid=[]\n",
        "  score = []\n",
        "  m_score= []\n",
        "  last = '*'\n",
        "  for i in range(64):\n",
        "    max = -4\n",
        "    w = '*'\n",
        "    for j in range(len(p[i])):\n",
        "      if p[i][j]>max:\n",
        "        max = p[i][j]\n",
        "        w = index_word_dict[j]\n",
        "    mid.append(w)   \n",
        "#     print(w,last,m_score,score)\n",
        "    if w != '*':\n",
        "      m_score.append(max)\n",
        "    elif w == '*' and last!='*':\n",
        "      score.append(m_score)\n",
        "      m_score = []\n",
        "    last = w\n",
        "  mid = ''.join(mid)\n",
        "  for i in range(10):\n",
        "    mid = mid.replace('**','*')\n",
        "  if mid[:1] == '*':\n",
        "    mid = mid[1:]\n",
        "  if mid[-1:] == '*':\n",
        "    mid = mid[:-1]\n",
        "  mids = mid.split('*') \n",
        "  \n",
        "#   print(score)\n",
        "  for index,m in enumerate(mids):\n",
        "    dist = []\n",
        "    r_dist = []\n",
        "    scs = {}\n",
        "    last = '*'\n",
        "    st = 0\n",
        "    lx = 0\n",
        "    for ii,sm in enumerate(m):\n",
        "      sco = score[index][ii]\n",
        "      if sco<0:\n",
        "          sco = math.exp(sco)\n",
        "      if ii == 0 :\n",
        "        dist.append(st)\n",
        "        r_dist.append(sm)\n",
        "        scs[st] = sco\n",
        "        last = sm\n",
        "      elif sm == last and lx < 4:\n",
        "        lx = lx + 1\n",
        "        scs[st] = scs[st] + sco\n",
        "      elif lx>4:\n",
        "        lx = 0\n",
        "        st = st + 1\n",
        "        last = sm\n",
        "        dist.append(st)\n",
        "        r_dist.append(sm)\n",
        "        scs[st] = sco\n",
        "      else:\n",
        "        lx = 0\n",
        "        st = st + 1\n",
        "        last = sm\n",
        "        dist.append(st)\n",
        "        r_dist.append(sm)\n",
        "        scs[st] = sco\n",
        "#       if sm not in dist:\n",
        "#         dist.append(sm)\n",
        "#       if scs.has_key(sm):\n",
        "#         sco = score[index][ii]\n",
        "#         if score[index][ii]<0:\n",
        "#           sco = math.exp(sco)\n",
        "#         scs[sm] = scs[sm] + sco\n",
        "#       else:\n",
        "#         scs[sm] = score[index][ii]\n",
        "    scs = sorted(scs.items(),key = lambda item:item[1],reverse=True)\n",
        "    \n",
        "    if len(m)<5:\n",
        "      scs = dict(scs[:1])\n",
        "      for i,d in enumerate(dist):\n",
        "        if d in scs.keys():\n",
        "          result.append(r_dist[i])\n",
        "    elif len(m)<9:\n",
        "      scs = dict(scs[:2])\n",
        "      for i,d in enumerate(dist):\n",
        "        if d in scs.keys():\n",
        "          result.append(r_dist[i])\n",
        "    elif len(m)<12:\n",
        "      scs = dict(scs[:3])\n",
        "      for i,d in enumerate(dist):\n",
        "        if d in scs.keys():\n",
        "          result.append(r_dist[i])\n",
        "    else:\n",
        "      scs = dict(scs[:4])\n",
        "      for i,d in enumerate(dist):\n",
        "        if d in scs.keys():\n",
        "          result.append(r_dist[i])\n",
        "  return  ''.join(result)    \n",
        "#   print(mid)\n",
        "#   print(score)\n",
        "data = pd.read_csv('./ocr_densenet/data/result/21_test_result.csv')\n",
        "i = 0 \n",
        "for index, row in data.iterrows():\n",
        "  name = row['name']\n",
        "  label = row['label']\n",
        "  prob = probs[index:index+1][0][0]\n",
        "  if not re.match(r'\\D(\\D\\d|\\d\\D)\\d{7}',label) or len(label)!=10:\n",
        "    r = pst10(prob)\n",
        "    print(index,name,label,r)\n",
        "    if len(r)>10: \n",
        "      rr = pgt10(prob) \n",
        "      print(index,name,label,r,rr)\n",
        "      if len(rr)!=10:\n",
        "        i = i + 1\n",
        "        print('/******\\n')\n",
        "        print('bt......10',index,name,label,r,rr)\n",
        "        print('\\n******/')\n",
        "        data.loc[data['name']==name,'label'] = rr[len(rr)-10:]\n",
        "      else:\n",
        "        data.loc[data['name']==name,'label'] = rr\n",
        "    else:\n",
        "      data.loc[data['name']==name,'label'] = r\n",
        "print(i)\n",
        "data.to_csv('./old_densent_rg_result.csv',index=False)\n",
        "print(i)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(10000,)\n",
            "*************CCC*77***WWW*7779999*22222222444*9999*222**********\n",
            "(286, '10G7SLEY.jpg', 'C7W792492', u'C7W7922492')\n",
            "*************FFF***PPP*44*777*0002222222*11*888*888*************\n",
            "(347, '18E5AHRD.jpg', 'FP4702188', u'FP47022188')\n",
            "***************HHH888**YYY*6666444*22222222999*777*555**********\n",
            "(353, '1905G3Q4.jpg', 'H8Y642975', u'H8Y6422975')\n",
            "*************PPPP**CCC*555*000*888*6662222*11*22222222**********\n",
            "(366, '1BE8SPIU.jpg', 'PC5086212', u'PC50862122')\n",
            "*************FFFF**XX*111*0002222222*888111*222888**************\n",
            "(529, '1W8GLXRM.jpg', 'FX1028128', u'FX10228128')\n",
            "*************ZZZZ*GGG*555*2222222*666*444999*888*666************\n",
            "(607, '27G1FQHB.jpg', 'ZG5264986', u'ZG52264986')\n",
            "******AA*****1*QQ*11**100Q******00*****4666*******Q*****588*****\n",
            "(661, '2D9QKGRM.jpg', 'A64', u'A1Q110Q046Q58')\n",
            "(661, '2D9QKGRM.jpg', 'A64', u'A1Q110Q046Q58', u'A1Q1006Q8')\n",
            "/******\n",
            "\n",
            "('bt......10', 661, '2D9QKGRM.jpg', 'A64', u'A1Q110Q046Q58', u'A1Q1006Q8')\n",
            "\n",
            "******/\n",
            "***************HHHH77***44*888*666*88*666*000*444999************\n",
            "(822, '2WHO9AQP.jpg', 'H748686049', u'H748686049')\n",
            "***************44***PPP*777*777000*333*333*444*11***************\n",
            "(992, '3H9QCNAV.jpg', '4P7703341', u'4P7703341')\n",
            "********TT**AA***YYY*333*555*111*333*222*555**11*555************\n",
            "(1135, '3ZYIPRKF.jpg', 'TAY35132515', u'TAY35132515')\n",
            "(1135, '3ZYIPRKF.jpg', 'TAY35132515', u'TAY35132515', u'TAY35132515')\n",
            "/******\n",
            "\n",
            "('bt......10', 1135, '3ZYIPRKF.jpg', 'TAY35132515', u'TAY35132515', u'TAY35132515')\n",
            "\n",
            "******/\n",
            "**************DD**RPP**6H*99*111*5556666777733*333**************\n",
            "(1546, '5I913BSM.jpg', 'RP9156733', u'DRP6H9156733')\n",
            "(1546, '5I913BSM.jpg', 'RP9156733', u'DRP6H9156733', u'DP69156733')\n",
            "*************RRR**66**JJJ*7777888*888*444555*22222222***********\n",
            "(1588, '5OUITVE4.jpg', 'R6J788452', u'R6J7884522')\n",
            "***********YY**666***AA**2222*666*111*2222*777*222*333***11*****\n",
            "(1955, '6ZL3SRCH.jpg', 'Y6A26127231', u'Y6A26127231')\n",
            "(1955, '6ZL3SRCH.jpg', 'Y6A26127231', u'Y6A26127231', u'Y6A26127231')\n",
            "/******\n",
            "\n",
            "('bt......10', 1955, '6ZL3SRCH.jpg', 'Y6A26127231', u'Y6A26127231', u'Y6A26127231')\n",
            "\n",
            "******/\n",
            "***************HH*888*YYY**666*44422222222000*444*000***********\n",
            "(2002, '75SQP2TG.jpg', 'H8Y642040', u'H8Y6422040')\n",
            "************LLLL2222**TTT*666*441*2222444*7777000*333***********\n",
            "(2077, '7GLKWOHV.jpg', 'L2T624703', u'L2T64124703')\n",
            "(2077, '7GLKWOHV.jpg', 'L2T624703', u'L2T64124703', u'L2T6424703')\n",
            "**************3*****11**1122411*2*839999910**55*2233************\n",
            "(2084, '7GY81NBZ.jpg', '11195', u'3112412839910523')\n",
            "(2084, '7GY81NBZ.jpg', '11195', u'3112412839910523', u'3111291052')\n",
            "***********UUU*999***EEE*2222*888*444*888*22223333*777***11*****\n",
            "(2131, '7O5CU34L.jpg', 'U9E28482371', u'U9E28482371')\n",
            "(2131, '7O5CU34L.jpg', 'U9E28482371', u'U9E28482371', u'U9E28482371')\n",
            "/******\n",
            "\n",
            "('bt......10', 2131, '7O5CU34L.jpg', 'U9E28482371', u'U9E28482371', u'U9E28482371')\n",
            "\n",
            "******/\n",
            "*************XXX*7777*LLL*22224444333*2222222*777*888***********\n",
            "(2353, '8HNCRF7B.jpg', 'X7L243278', u'X7L2432278')\n",
            "**************FFFF**UU**44*666*00022222222888555*000************\n",
            "(2474, '8YUG24DX.jpg', 'FU4602850', u'FU46022850')\n",
            "*************SSSS**KKK*000*111*999*2222222888*000*333***********\n",
            "(2691, '9R27YVKG.jpg', 'SK0192803', u'SK01922803')\n",
            "**************DD**XXX*3331111999922222222222*1113333************\n",
            "(2961, 'AQ7D5GLC.jpg', 'DX3192213', u'DX31922213')\n",
            "*************EEE*666**MMM*6666*444999*000*111*22222222**********\n",
            "(2992, 'AU5GN3VR.jpg', 'E6M649012', u'E6M6490122')\n",
            "**************ZZZ*GGG*2222222999*999**11*555*666*444************\n",
            "(3018, 'AXCOQZH5.jpg', 'ZG2991564', u'ZG22991564')\n",
            "*************TTT**EEE*555*6662222222*777*888111*777*************\n",
            "(3043, 'B05C8YI2.jpg', 'TE5627817', u'TE56227817')\n",
            "*********MM***II***BBB**777**777*444**222*888**666**555*********\n",
            "(3128, 'BCO821S0.jpg', 'MB7742865', u'MIB7742865')\n",
            "************SDD***PHY*111*555*444*0003333*777*6663333***********\n",
            "(3147, 'BEDG8TNF.jpg', 'DHP15403763', u'SDPHY15403763')\n",
            "(3147, 'BEDG8TNF.jpg', 'DHP15403763', u'SDPHY15403763', u'DH15403763')\n",
            "************MA*444**PPP*77777777*11*333*444*777*000*************\n",
            "(3177, 'BGZEMVNG.jpg', '4P7713470', u'MA4P7713470')\n",
            "(3177, 'BGZEMVNG.jpg', '4P7713470', u'MA4P7713470', u'M4P7713470')\n",
            "*************PPP***NN**00022222222999*888333*555*2222***********\n",
            "(3439, 'CEMQPS06.jpg', 'PN0298352', u'PN02298352')\n",
            "***************CCC*NN**3337777444*666888*11122222222************\n",
            "(3549, 'CPKHRX52.jpg', 'CN3746812', u'CN37468122')\n",
            "**************UUU**JJJ*111*666*2222222000*222*0000000***********\n",
            "(3578, 'CU5Z9G1O.jpg', 'UJ1620200', u'UJ16220200')\n",
            "***************HHH*UUU*999*444**56*444*888*666999*2222**********\n",
            "(3714, 'DC6ZKG3A.jpg', 'HU945648692', u'HU945648692')\n",
            "(3714, 'DC6ZKG3A.jpg', 'HU945648692', u'HU945648692', u'HU94548692')\n",
            "**************MM*444*PPPP*7777777222222223338888999*************\n",
            "(3904, 'E1WYDGK4.jpg', 'M4P772389', u'M4P7722389')\n",
            "****************HHH**ZZZ7770000999*88*555*222*55*000************\n",
            "(4006, 'EF5UCTW3.jpg', 'HZ7095250', u'HZ70985250')\n",
            "**********CC999*GGG99922200000*888556666***11*M0*223*000********\n",
            "(4041, 'EIW0G8BZ.jpg', 'C9G920856', u'C9G92008561M0230')\n",
            "(4041, 'EIW0G8BZ.jpg', 'C9G920856', u'C9G92008561M0230', u'C9G9208561M20')\n",
            "/******\n",
            "\n",
            "('bt......10', 4041, 'EIW0G8BZ.jpg', 'C9G920856', u'C9G92008561M0230', u'C9G9208561M20')\n",
            "\n",
            "******/\n",
            "*************EEE*222*RRR*888*000111*9992222222*777**************\n",
            "(4469, 'G14M6DTG.jpg', 'E2R801927', u'E2R8019227')\n",
            "**************XXX*777**LLL*222444*222*111111*2222222************\n",
            "(4667, 'GD7VS2MB.jpg', 'X7L242112', u'X7L2421122')\n",
            "***************HHH1111*PPP**44477775555333**2222222111**********\n",
            "(4679, 'GDQYX8UR.jpg', 'H1P475321', u'H1P4753221')\n",
            "***********PPP**OOO*999**444*888*77777777*444*333**111**********\n",
            "(4717, 'GG2XMQ0I.jpg', 'P94877431', u'PO94877431')\n",
            "**************LLL*88***RR*888*111*666*777666*111*333************\n",
            "(4739, 'GH1B5Y9L.jpg', 'LR8167613', u'L8R8167613')\n",
            "***************RRR**NN**888*666000*2222222*666*222333***********\n",
            "(4835, 'GO174EUG.jpg', 'RN8602623', u'RN86022623')\n",
            "****************HHHITYYY8111*333*22*777*44*555444433************\n",
            "(4896, 'GRCX27WS.jpg', 'Y1327454', u'HITY813274543')\n",
            "(4896, 'GRCX27WS.jpg', 'Y1327454', u'HITY813274543', u'HY813274543')\n",
            "/******\n",
            "\n",
            "('bt......10', 4896, 'GRCX27WS.jpg', 'Y1327454', u'HITY813274543', u'HY813274543')\n",
            "\n",
            "******/\n",
            "*************PPP**NN**11*666*777666*444555*2222222**************\n",
            "(5029, 'GZRXDL16.jpg', 'PN1676452', u'PN16764522')\n",
            "**************WW***BBB*444333**33*333*5559999999*2222***********\n",
            "(6084, 'LQNZ872P.jpg', 'WB439335992', u'WB43335992')\n",
            "**************III**ZZ*444*555555*2222222*666111*333*************\n",
            "(6242, 'MB60L738.jpg', 'IZ4552613', u'IZ45522613')\n",
            "***********RRR**GG**666*2222333**11**886*333*999**999***********\n",
            "(6573, 'NIVCQYGH.jpg', 'RG623168399', u'RG623186399')\n",
            "(6573, 'NIVCQYGH.jpg', 'RG623168399', u'RG623186399', u'RG62318399')\n",
            "***************PPP**NN**5552222222*777555*777*55*333************\n",
            "(6666, 'NWY9GC8S.jpg', 'PN5275753', u'PN52275753')\n",
            "*************HHH**ZZZ*38**333*111*555*888*444*444*777***********\n",
            "(6703, 'O24YRI1T.jpg', 'HZ3158447', u'HZ383158447')\n",
            "(6703, 'O24YRI1T.jpg', 'HZ3158447', u'HZ383158447', u'HZ33158447')\n",
            "************SSSS**KKK*0000*11*999*22222222888*000*111***********\n",
            "(6892, 'OPZ6R2QM.jpg', 'SK0192801', u'SK01922801')\n",
            "************III***WW**444*555*33**888*2222333*888*333***********\n",
            "(6985, 'P1KRXC24.jpg', 'IW4582383', u'IW45382383')\n",
            "*********LLMG44****3EE774494166***********Y***66***44***********\n",
            "(7027, 'P5MUY42D.jpg', '7', u'LMG43E749416Y64')\n",
            "(7027, 'P5MUY42D.jpg', '7', u'LMG43E749416Y64', u'L4E746Y64')\n",
            "/******\n",
            "\n",
            "('bt......10', 7027, 'P5MUY42D.jpg', '7', u'LMG43E749416Y64', u'L4E746Y64')\n",
            "\n",
            "******/\n",
            "***********LLL2222*TTTT*555*777*000*111*666*999*777*************\n",
            "(7276, 'Q1O80FS6.jpg', '2T5701697', u'L2T5701697')\n",
            "**************YYY**LLL*66622222222222888*22222227777************\n",
            "(7374, 'QCNIH0FY.jpg', 'YL628227', u'YL62228227')\n",
            "***********CCC**000***MM***666*444**666**666*555**000*666*******\n",
            "(7644, 'RCS53E72.jpg', 'C0M64665096', u'C0M6466506')\n",
            "**************TTT*222**AA**666888888822222222999*000************\n",
            "(8066, 'SVELDQW2.jpg', 'T2A688290', u'T2A6882290')\n",
            "************UUU*777**DDD*111*000*000*111*444*2222222************\n",
            "(8085, 'SYZ1HDVF.jpg', 'U7D100142', u'U7D1001422')\n",
            "**************TTT**HH*9992222333*77772222222*888111*************\n",
            "(8092, 'T05DLC4R.jpg', 'TH9237281', u'TH92372281')\n",
            "**************PPP**GG**666*2222222222*0002222999*2222***********\n",
            "(8231, 'TH8D40K9.jpg', 'PG6220292', u'PG62220292')\n",
            "**************UUU**AAA*000*22222229999*111999*000*999***********\n",
            "(8517, 'UGISMXD1.jpg', 'UA0291909', u'UA02291909')\n",
            "****************DD***YY*777*666*10*333*444333*888*666***********\n",
            "(8545, 'UK5T3LX9.jpg', 'DY7634386', u'DY761034386')\n",
            "(8545, 'UK5T3LX9.jpg', 'DY7634386', u'DY761034386', u'DY76034386')\n",
            "************MM**RRR*000**888*333*7777*222*000*7777*000**********\n",
            "(8572, 'UMK53ZPL.jpg', 'MR083720709', u'MR08372070')\n",
            "**************XX**4WW**DD*11111110000333*111*888888*************\n",
            "(8688, 'V2T7DSBG.jpg', 'XD103188', u'X4WD1103188')\n",
            "(8688, 'V2T7DSBG.jpg', 'XD103188', u'X4WD1103188', u'XWD1103188')\n",
            "**************CCCC999**GGC*999*777*66*5555333*666333************\n",
            "(9177, 'WVA3EUBC.jpg', 'C9GC9765363', u'C9GC9765363')\n",
            "(9177, 'WVA3EUBC.jpg', 'C9GC9765363', u'C9GC9765363', u'C9G9765363')\n",
            "***********T****HHH*WW**111777*222444*6667777777*111************\n",
            "(9222, 'X2UC4LON.jpg', 'THW17246771', u'THW17246771')\n",
            "(9222, 'X2UC4LON.jpg', 'THW17246771', u'THW17246771', u'THW17246771')\n",
            "/******\n",
            "\n",
            "('bt......10', 9222, 'X2UC4LON.jpg', 'THW17246771', u'THW17246771', u'THW17246771')\n",
            "\n",
            "******/\n",
            "************EEE*LLL*77777777777999*333*8886666666***************\n",
            "(9280, 'X9TH3OK4.jpg', 'EL7793866', u'EL77793866')\n",
            "*************BBB*888**YYY**44*999*666*2222222*444*999***********\n",
            "(9304, 'XD7GE198.jpg', 'B8Y496249', u'B8Y4962249')\n",
            "*************HHH*PPP*999**444*7777*99*2222*999**444*999*********\n",
            "(9310, 'XDWQFA84.jpg', 'HP947902949', u'HP94792949')\n",
            "*************KK**PPP*2222222*111*222222227777*444*111***********\n",
            "(9462, 'Y1RI32GW.jpg', 'KP2212741', u'KP22122741')\n",
            "************GGG***PP**000*333**99**2222*11**88**999*000*********\n",
            "(9525, 'Y8WBKPGF.jpg', 'G03921890', u'GP03921890')\n",
            "********TT***GG***YY**2222333**222*888*333*888*6666*111*********\n",
            "(9526, 'Y8XGGIM6.jpg', 'TGY23283861', u'TGY23283861')\n",
            "(9526, 'Y8XGGIM6.jpg', 'TGY23283861', u'TGY23283861', u'TGY23283861')\n",
            "/******\n",
            "\n",
            "('bt......10', 9526, 'Y8XGGIM6.jpg', 'TGY23283861', u'TGY23283861', u'TGY23283861')\n",
            "\n",
            "******/\n",
            "**************UUU*777**DDD*111*000*444222222222223333***********\n",
            "(9558, 'YDECXWNM.jpg', 'U7D104223', u'U7D1042223')\n",
            "***************HH**RR**111444*111*2222222999*11*333*************\n",
            "(9599, 'YKIP4B0E.jpg', 'HR1412913', u'HR14122913')\n",
            "*************XX*7777**LLL*222*444*111*888*88822222222***********\n",
            "(9668, 'YU02OGWG.jpg', 'X7L241882', u'X7L2418822')\n",
            "*************TT*JJJ*22222222333*6669999*333*3335555*************\n",
            "(9781, 'Z7HB2SEL.jpg', 'TJ2369335', u'TJ22369335')\n",
            "*************UUU**OOO*222222222222333**666888*0000999***********\n",
            "(9936, 'ZROGN6UI.jpg', 'UO2236809', u'UO22236809')\n",
            "9\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WGAkJHixA-Bd",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dS93Df49fA1E",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cCB0U_oy53rH",
        "colab_type": "text"
      },
      "source": [
        "### 可视化不同模型检测不一致的情况,重新剪裁图片"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Lww5qDAMoLm8",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import os\n",
        "from shutil import copyfile\n",
        "from PIL import Image\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "def drow(img):\n",
        "  img = Image.open('/content/test_cptn_result/'+img)\n",
        "#   .convert('L')\n",
        "#   img = img.resize((160,32), Image.ANTIALIAS)\n",
        "  plt.imshow(img, cmap='gray')\n",
        "  plt.show()\n",
        "  \n",
        "import pandas as pd\n",
        "label1_data = pd.read_csv('./cptn-crnn/crnn/crnn_train_result_0606.csv')\n",
        "label2_data = pd.read_csv('./densent_rg_result.csv')\n",
        "label2_data['label']=label2_data['label'].map(str.strip)\n",
        "\n",
        "i = 0\n",
        "for index, row in label1_data.iterrows():\n",
        "  name = row['name']\n",
        "  label1 = row['label']\n",
        "  try:\n",
        "    label2 = label2_data[label2_data['name']==name]['label'].values[0].strip()\n",
        "    if label1!=label2:\n",
        "      if not os.path.exists(os.path.join('./train_cptn_result',name)):\n",
        "              print('%s does not exist' % imagePath)\n",
        "              continue\n",
        "      copyfile(os.path.join('./train_cptn_result',name),'./train_cptn_result_repair/'+name)\n",
        "      i = i +1\n",
        "      print(index,row['name'],label1,label2,drow(row['name']))\n",
        "  except:\n",
        "    continue\n",
        "print(i)"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}